
///////////////////////////////////////////////////////////////////////////
//	Class: Pipe - Create a pipe with length is NUM_PIPE_LINE which is set in ADUConstant.h
//	Dev: DungNT
//	Usage: 	
//		Pipe* mPipe = new Pipe();
//		mPipe->createPipe(_layer);
///////////////////////////////////////////////////////////////////////////


#ifndef __ADU_PIPE_H__
#define __ADU_PIPE_H__

#include "cocos2d.h"
#include "ADUConstant.h"
USING_NS_CC;
using namespace std;



class PipeHead : public Sprite {
	public:
		PipeHead() {};
		~PipeHead(){};
		static PipeHead* createPipeHead(const string& file);
		bool 			 initPipeHeadWithFile(const string& file);
	private:
		EventListenerTouchOneByOne* mTouchListener;
};


class PipeCircle : public Sprite {
	public:
		PipeCircle(){};
		~PipeCircle(){};
		static PipeCircle* 	createPipeCircle(const string& file);
		void 				enableTouch();
		void 				setPipe(SpriteBatchNode* _pipe) {mPipeLine = _pipe;};
		SpriteBatchNode* 	getPipe() {return mPipeLine;};

		void 				setPipeHead(PipeHead* _pipe) {mPipeHead = _pipe;};
		PipeHead* 			getPipeHead() {return mPipeHead;};
		
		virtual bool 		onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event);
		virtual void 		onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event);
		virtual void 		onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event);
		virtual void 		onTouchCancelled(cocos2d::Touch *touch, cocos2d::Event *event);
	private:
		EventListenerTouchOneByOne* mTouchListener;
		SpriteBatchNode* 		mPipeLine;
		PipeHead* 				mPipeHead;
		Vec2					mStartPosHead;
		bool					mPipeHeadTouch;
		bool					mCircleTouch;
};




class Pipe : public Node {
	public:
		Pipe(){};
		~Pipe(){};
		void createPipe(Node* _layer);
		Vec2 getPipeHeadPosition() { return mPipeHead->getPosition();};
	private:
		PipeCircle* 		mPipeCircle;
		PipeHead* 			mPipeHead;
		Sprite* 			mPipeSeg[NUM_PIPE_LINE];		// pipe segment
		SpriteBatchNode* 	mPipeLine;
		Vec2 				mLastSegPos;
};

#endif
